package com.study.hot.jetpack.databinding.model;

import android.widget.ImageView;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.study.hot.BR;

/**
 * <pre>
 *     author : slx
 *     time   : 2021/02/08
 *     desc   :
 * </pre>
 */
public class User extends BaseObservable {
    private String name;
    private String password;
    private String avatar;
    private boolean isShow;

    public User() {
    }

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    public User(String name, String password, String avatar) {
        this.name = name;
        this.password = password;
        this.avatar = avatar;
    }

    //自定义属性绑定
    @BindingAdapter("avatar")
    public static void bindAvatar(ImageView iv, String url) {
        Glide.with(iv.getContext()).load(url).into(iv);
    }

    @Bindable
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        notifyPropertyChanged(BR.name);
    }

    @Bindable
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
        notifyPropertyChanged(BR.password);
    }

    @Bindable
    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
        notifyPropertyChanged(BR.avatar);
    }

    public boolean isShow() {
        return isShow;
    }

    public void setShow(boolean show) {
        isShow = show;
    }

    @Override public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
